home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / UTILITIE / CONVERSI / 1396.ZIP / STRIP.ARC / STRIP301.BAS < prev   
BASIC Source File  |  1988-06-04  |  11KB  |  297 lines

  1. '
  2. ' STRIP301.BAS -- Program to strip leading characters from any text file.
  3. ' ~~~~~~~~~~~~    -------------------------------------------------------
  4. '                 Author - Chip Morrow
  5. '                          40 Valley View Dr.
  6. '                          Newark, OH 43055
  7. '
  8. '                 Version 3.01 finished June 4, 1988 - released as Shareware.
  9. '                 This program is not copyrighted, I ask only that you
  10. '                 acknowledge it if you use any of my code in your own
  11. '                 programs. Thanks!
  12. '
  13. '  *************************************************
  14. '  *  Go to error handling routine if one occurs.  *
  15. '  *************************************************
  16. '
  17.  5 on error goto 3000
  18.  
  19. '  **********************************************************************
  20. '  *  Line 6 is ERL check for the existence of the configuration file.  *
  21. '  **********************************************************************
  22. '
  23.  6 defint a-z
  24.    open "STRIP.CNF" for input as #1
  25.    input #1,STRIPNUM
  26.       if STRIPNUM < 1 or STRIPNUM > 3 then goto cnf.error
  27.       for x = 1 to STRIPNUM
  28.          input #1,strip.temp$
  29.          if x = 1 then strip1$ = strip.temp$
  30.          if x = 2 then strip2$ = strip.temp$
  31.          if x = 3 then strip3$ = strip.temp$
  32.       next
  33.    close
  34.  
  35. '  *******************************************************
  36. '  *  Check for parameters entered on the command line.  *
  37. '  *******************************************************
  38. '
  39.    If Command$ = "*" goto command.line.cnf
  40.    If Command$ = "h" or Command$ = "H" goto 1000
  41.    If Command$ = "?" goto 1000
  42.    If Command$ = "help" or Command$ = "HELP" goto 1000
  43.    If Command$ = "" then gosub 4000 : goto 10
  44.       gosub 3010 : f$ = COMMAND1$ : new$ = COMMAND2$ : GOTO 12
  45.  
  46. 10 '
  47.    ' ********************************************************************
  48.    ' *  No parameters were entered on the command line. Get filenames.  *
  49.    ' ********************************************************************
  50.    '
  51.    Defint a-z : cls
  52.     locate 20,1 : Line input "Enter SOURCE filename --> ",F$
  53.     locate 20,1 : print space$(70)
  54.               if F$ = "" goto 1000
  55.     locate 20,1 : Line input "Save changes to --------> ",NEW$
  56.                       cls
  57.  
  58. 12 '
  59.    ' ***************************************************************
  60.    ' * Line 12 is GOTO line in case the variables are already set. *
  61.    ' * Last check for no filenames.                                *
  62.    ' ***************************************************************
  63.    '
  64.    gosub 4000
  65.    If len(f$) < 1 then goto 1000
  66.    if len(new$) < 1 then gosub 2000
  67.    name f$ as f$
  68.  
  69. 15 '
  70.    ' *****************************************************************
  71.    ' * Line 15 is a RESUME line for error #58 (File already exists). *
  72.    ' * Normal file opening starts here.                              *
  73.    ' *****************************************************************
  74.    '
  75.    Open f$ for input as #1
  76.    total$ = str$(lof(1))
  77.    Open new$ for output as #2
  78.    x$ = "SOURCE file <" + F$ + "> ----" + total$
  79.    locate 3,1 : print x$
  80.    x$ = "OBJECT file <" + NEW$ + "> ---- "
  81.    locate 4,1 : print x$ 
  82.    linenum = 1
  83.  
  84. 30 '
  85.    ' ********************************************************************
  86.    ' * Code re-written here for version 3.00. Input by line instead of  *
  87.    ' * byte-for-byte as it was previously. MUCH faster execution.       *
  88.    ' ********************************************************************
  89.    '
  90.    line input #1,TEXT$
  91.    linenum = linenum + 1
  92.    goto 30
  93.  
  94. 35 linenum = (linenum - 1)
  95.    close 1
  96.    open f$ for input as #1
  97.    counter = 1
  98.      while not eof(1)
  99.        gosub file.input
  100.        counter = counter + 1
  101.      wend
  102.    goto 37
  103.  
  104. file.input:
  105.    line input #1,text$
  106.      locate 6,1 : print "Converting line number"counter
  107.           if left$(text$,1) = STRIP1$ or _
  108.              left$(text$,1) = STRIP2$ and stripnum > 1 or _
  109.              left$(text$,1) = STRIP3$ and stripnum > 2 then gosub 40
  110.      print #2,text$
  111.    return
  112.  
  113. 37 '
  114.    ' ***********************************************************************
  115.    ' *  End of conversion. Close files, check length of file just created, *
  116.    ' *  print the info, and exit to DOS.                                   *
  117.    ' ***********************************************************************
  118.    '
  119.    close
  120.      open new$ as #1 len = 1
  121.        new.total$ = str$(lof(1))
  122.        close 
  123.      x$ = "OBJECT file <" + NEW$ + "> ----" + new.total$
  124.      locate 4,1 : print space$(78)
  125.    locate 4,1 : print x$ : locate 6,1 : print space$(78)
  126.    locate 6,1 : print linenum "lines processed." : end
  127.  
  128. 40 '
  129.    ' ***************************************************************
  130.    ' * Subroutine to strip the offending characters one at a time. *
  131.    ' ***************************************************************
  132.    '
  133.    y = len(text$)
  134.      if y < 1 then return
  135.      new.text$ = mid$(text$,2,(y-1))
  136.      text$ = new.text$
  137.        if left$(text$,1) = STRIP1$ or _
  138.           left$(text$,1) = STRIP2$ and stripnum > 1 or _
  139.           left$(text$,1) = STRIP3$ and stripnum > 2 then goto 40
  140.    return
  141.  
  142. 1000 '
  143.      ' **********************************
  144.      ' * Routine to display help info.  *
  145.      ' **********************************
  146.      '
  147.      cls
  148.      Print _
  149.      "STRIP.COM version 3.01 by Chip Morrow - June 4, 1988" CHR$(13) CHR$(13) _
  150.      "Delete leading characters from lines within text files." CHR$(13) CHR$(13) _
  151.      "Usage:" CHR$(13) CHR$(13)_
  152.      "STRIP source.fil object.fil              - or -" CHR$(13) _
  153.      "STRIP source.fil                         - or -" CHR$(13) _
  154.      "STRIP * to create new configuration file - or -" CHR$(13) _
  155.      "STRIP ? to display this message" CHR$(13) CHR$(13) 
  156.      end
  157.  
  158. 2000 '
  159.      ' ********************************************************************
  160.      ' *  Routine to default the object file name to the source file name *
  161.      ' *  with the extension .FIX.                                        *
  162.      ' ********************************************************************
  163.      '
  164.      DEFAULTF$ = ""
  165.      CASE = 0
  166.      FOR X = 1 TO LEN(F$)
  167.      IF POINTER = 1 GOTO 2050
  168.      MID$(F$,X,1) = CHR$(ASC(MID$(F$,X,1)))
  169.             ZZ = ASC(MID$(F$,X,1))
  170.          IF ZZ > 64 and ZZ < 90 then case = 1
  171.          IF ZZ = 46 then goto 2043
  172.      DEFAULTF$ = DEFAULTF$ + CHR$(ZZ)
  173.      GOTO 2050
  174. 2043 POINTER = 1
  175.       GOTO 2050
  176. 2050 NEXT X
  177.      IF CASE = 0 then FIX$ = ".fix"
  178.      IF CASE = 1 then FIX$ = ".FIX"
  179.      DEFAULTF$ = DEFAULTF$ + FIX$ : NEW$ = DEFAULTF$ : return
  180.  
  181. 3000 '
  182.      ' *********************************************************
  183.      ' *  The main error handler. All errors pass this way...  *
  184.      ' *********************************************************
  185.      '
  186.      IF ERR = 52 and ERL = 35 then resume cnf.error
  187.      IF ERR = 52 and ERL = 15 then print "Incomplete OBJECT file name." : end
  188.      IF ERR = 53 and ERL = 6 then resume create
  189.      IF ERR = 53 then print "SOURCE file <"F$"> not found." : end
  190.      IF ERR = 55 and ERL = 15 then print "SOURCE and OBJECT file names cannot be identical." : end
  191.      IF ERR = 58 then resume 15
  192.      IF ERR = 62 then resume 35
  193.      IF ERR = 64 then print "Invalid filespec." : end
  194.      IF ERR = 76 then print "Invalid path/filepec" : end
  195.     PRINT "An untrapped error has occurred."
  196.         print
  197.         print "Most common causes:"
  198.         print 
  199.         print "- Invalid path name for the source or object file."
  200.         print : print "- Disk door open when attempting to read/write to floppy."
  201.         print : print "- Out of disk space."
  202.         print : print "Error number"ERR"in line number"ERL"."
  203.      END
  204.  
  205. 3010 '
  206.      ' ***********************************************
  207.      ' *  Routine to handle command line parameters. *
  208.      ' ***********************************************
  209.      '
  210.      POINTER = 0
  211.      CONVERT$ = COMMAND$
  212.      COMMAND1$ = ""
  213.      COMMAND2$ = ""
  214.      FOR X = 1 TO LEN(COMMAND$)
  215.      MID$(CONVERT$,X,1) = CHR$(ASC(MID$(CONVERT$,X,1)))
  216.             ZZ = ASC(MID$(CONVERT$,X,1))
  217.          IF X = 1 THEN GOTO 3030
  218.          IF ZZ = 32 and pointer = 1 then pointer = 2 : goto 3050
  219.          IF ZZ = 44 and pointer = 1 then pointer = 2 : goto 3050
  220.          IF ZZ = 32 then pointer = 1 : goto 3050
  221.          IF ZZ = 44 then pointer = 1 : goto 3050
  222.          IF POINTER = 1 THEN GOTO 3020
  223.          IF POINTER = 2 THEN GOTO 3050
  224.      COMMAND1$ = COMMAND1$ + CHR$(ZZ)
  225.          GOTO 3050
  226.  
  227. 3020 COMMAND2$ = COMMAND2$ + CHR$(ZZ)
  228.          GOTO 3050
  229.  
  230. 3030 COMMAND1$ = COMMAND1$ + CHR$(ZZ)
  231.  
  232. 3050 NEXT X
  233.      if command2$ = "" then gosub 2000
  234.      RETURN
  235.  
  236. 4000 locate 1,1 : print "STRIP - V 3.01 by Chip Morrow" : return
  237.      
  238. create:
  239.    '
  240.    ' ********************************************************
  241.    ' * STRIP.CNF was not found. Create a new one, or exit.  *
  242.    ' ********************************************************
  243.    '
  244.    close
  245.    print "STRIP.CNF not found on default drive." : print
  246.    print "Press <ESC> to exit, any other key to create configuration file..."
  247.  
  248. create1:
  249.    create$ = inkey$
  250.      if create$ = CHR$(27) then end
  251.      if create$ = "" then goto create1
  252.    close : cls
  253.    x$ = "Number of characters to strip (1-3)? "
  254.    print x$
  255.  
  256. create2:
  257.      line1$ = inkey$
  258.      if line1$ = "1" or line1$ = "2" or line1$ = "3"  goto create3
  259.      if line1$ = "" goto create2
  260.      goto create2
  261.  
  262. create3:
  263.      locate 1,(len(x$)+1) : print line1$
  264.     open "STRIP.CNF" for output as #1
  265.         print #1,line1$
  266.           strip.chars = val(line1$)
  267.         line.num = 2
  268.         for x = 1 to strip.chars
  269.  
  270. create4:
  271.      strip.char$ = inkey$
  272.     char.num = line.num - 1
  273.     x$ = "Enter character #" + str$(char.num) + " to strip? "
  274.           locate line.num,1 : print x$
  275.           while strip.char$ = "" : goto create4 : wend
  276.           strip.val = asc(strip.char$)
  277.        locate line.num,(len(x$)+1) : print "ASCII code -" strip.val
  278.     print #1,chr$(34) + strip.char$ + chr$(34)
  279.     line.num = line.num + 1
  280.      next
  281.    close
  282.    locate 6,1 : print "Configuration file created."
  283.    end
  284.  
  285. cnf.error:
  286.    '
  287.    ' ***********************************************
  288.    ' *  Error trap for an invalid STRIP.CNF file.  *
  289.    ' ***********************************************
  290.    '
  291.    print "Configuration file STRIP.CNF is invalid."
  292.    print
  293.  
  294. command.line.cnf:
  295.    print "Press any key to create new STRIP.CNF file or <ESC> to exit..."
  296.    goto create1
  297.